#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>

#include "svdebug.hpp"

int g_current_dbg_level = LOG_LEVEL_DEBUG;

void log_fun(int level, const char *opt, const char* tag, int line, const char *func, const char *fmt, ...)
{
    if (level >= g_current_dbg_level) 
    {
        char msg_buf[20*1024];
        va_list ap; 
        va_start(ap,fmt);                                                                       
        sprintf(msg_buf,"%s/%s (%d): %s() ",opt, tag, line, func);
        vsprintf(msg_buf+strlen(msg_buf),fmt,ap);
        fprintf(stderr,"%s\n",msg_buf); /* 输出到标准输出 */
        va_end(ap);
    }

    return;
}

/* 设置 打印级别 */
void ModuleDebugInit(int level)
{
    g_current_dbg_level = level;
    return;
}